package com.boot.bootweb;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.AlipayConfig;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.internal.util.AntCertificationUtil;
import com.alipay.api.internal.util.file.FileUtils;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
import com.alipay.api.FileItem;
import static com.alipay.api.internal.util.file.Charsets.UTF_8;
import java.io.File;
import java.util.Base64;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * @author guoyunfei on 2022/2/11 0:48
 * @className AlipayFundTransUniTransfer
 * @description TODO
 * @Version 1.0
 */
public class AlipayFundTransUniTransfer {
    public static void main(String[] args) throws AlipayApiException {
        String privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCbwgOaIo6lz+5YdJriDWeNjC1852JLwNz3ewkq+156gM3vFCdL91kq5boTFfVGfE9I5vx3C5wYf6aPmBItbHvOlu7xjPNDTyr1WzlX1R9a4sKk2hvJbvhYzYBoisSABZfWMYuEvGiOU7tt+Okj5xqt3hgqvl4b4K+8liAZrKTGiF7+O5tV33z2N+ZvIXwqRwRRcFud484hd9BcL3RWKnEIviKgp5zgwwQ7VfFgKm7X3Tnq6x9UxOp4tXdruG9Ga6fYtIn6K3c5gYFru1TThO6j9uF33jOKbBuZGq9CZFyCE2DFYpjBNCozBnoQxDZigpBZtMVy3Sswto5mREs2Vbf/AgMBAAECggEBAJt3yW6lRasd4/Lo2Nv/szfnDlRZBJVGeYiQh3Memow+Ws9jV2INDzSxPszkIwFq/RxwatlMfk85wwAbMzGh0eZAY1o5bWrm76Mdnhwcf4KRSuWPSyMBn+PLo3s137NFY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F81W2XHrA==";

        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        //gateway:支付宝网关（固定）https://openapi.alipay.com/gateway.do
        certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");

        //APPID 即创建应用后生成,详情见创建应用并获取 APPID
        certAlipayRequest.setAppId("2021003118652038");

        //开发者应用私钥，由开发者自己生成
        certAlipayRequest.setPrivateKey(privateKey);

        //参数返回格式，只支持 json 格式
        certAlipayRequest.setFormat("json");

        //请求和签名使用的字符编码格式，支持 GBK和 UTF-8
        certAlipayRequest.setCharset("UTF-8");

        //商户生成签名字符串所使用的签名算法类型，目前支持 RSA2 和 RSA，推荐商家使用 RSA2。
        certAlipayRequest.setSignType("RSA2");

        //应用公钥证书路径（app_cert_path 文件绝对路径）
        certAlipayRequest.setCertPath("D:\\IDEA\\myproject\\platform-wallpaper-admin-v3.0\\src\\main\\resources\\cert\\xingg\\appCertPublicKey_2021003118652038.crt");
        //支付宝公钥证书文件路径（alipay_cert_path 文件绝对路径）
        certAlipayRequest.setAlipayPublicCertPath("D:\\IDEA\\myproject\\platform-wallpaper-admin-v3.0\\src\\main\\resources\\cert\\xingg\\alipayCertPublicKey_RSA2.crt");
        //支付宝CA根证书文件路径（alipay_root_cert_path 文件绝对路径）
        certAlipayRequest.setRootCertPath("D:\\IDEA\\myproject\\platform-wallpaper-admin-v3.0\\src\\main\\resources\\cert\\xingg\\alipayRootCert.crt");

        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();

        AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
        model.setOutBizNo(DateUtil.format(new Date(),"yyyyMMddHHmmssSS"));
        model.setRemark("星光壁纸提现");
        model.setBusinessParams("{\"payer_show_name_use_alias\":\"服务代理\"}");
        model.setBizScene("DIRECT_TRANSFER");

        Participant payeeInfo = new Participant();
        payeeInfo.setIdentity("18175760278");
        payeeInfo.setIdentityType("ALIPAY_LOGON_ID");
        payeeInfo.setName("郭云飞");

        model.setPayeeInfo(payeeInfo);
        model.setTransAmount("0.1");
        model.setProductCode("TRANS_ACCOUNT_NO_PWD");
        model.setOrderTitle("星光壁纸提现");
        request.setBizModel(model);

        AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
        if (response.isSuccess()) {
            System.out.println("调用成功");
            System.out.println(JSON.toJSONString(response));
        } else {
            System.out.println("调用失败");
        }
    }



}
